<html>
<head>
	<meta charset="UTF-8">
	<title>系统应用信息列表</title>
	<link id="easyuiTheme" href="../../static/easyui/themes/bootstrap/easyui.css" rel="stylesheet" type="text/css"/>
	<link href="../../static/easyui/themes/icon.css" rel="stylesheet" type="text/css"/>
	<script src="../../static/easyui/jquery.min.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.cookie.js" type="text/javascript"></script>
	<script src="../../static/easyui/ui-theme.js" type="text/javascript"></script>
	<script src="../../static/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../../static/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.util.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.jquery.ajax.js" type="text/javascript"></script>
	<script src="../../static/plugin/assets/jslib.easyui.util.js" type="text/javascript"></script>
	<script src="../../ffres/dict/all.js" type="text/javascript"></script>
	<link href="../../static/easyui/themes/frameless.css" rel="stylesheet" type="text/css"/>
	<a href="" target="_blank" id="commonLink" name="commonLink"></a>
</head>
<script type="text/javascript">
	var archType = 'S';  //$.getUrlParam('archType');
	var subsCode = $.getUrlParam('subsCode');

	function doCreateApp(){
		JLEUtil.createModalWin('应用创建步骤-选择应用模板', 'createAppStep1.html?sysId=' + $.getUrlParam('sysId') + '&archType=' + archType);
	}
	
	// 应用创建第二步
	function doCreateAppStep2(sysId,appTemplateId){
		JLEUtil.closewin();
		JLEUtil.createModalWin('应用创建步骤-选择表模型工程', 'createAppStep2.html?sysId=' + sysId + '&appTemplateId=' + appTemplateId);
	}
	
	// 应用创建第三步
	function doCreateAppStep3(sysId,appTemplateId,projectId,projectCode,projectName){
		JLEUtil.closewin();
		JLEUtil.createModalWin('应用创建步骤-填写应用基本信息', 'createAppStep3.html?sysId=' 
				+ sysId + '&appTemplateId=' + appTemplateId + '&projectId=' + projectId + '&projectCode='+projectCode + '&projectName=' + projectName 
				+ '&archType=' + archType);
	}
	
	function doUpdate() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('修改', 'PaasAppsInfoUpdate.html?' + 'appId=' + row.appId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doDelete(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			$.messager.confirm('删除提示', '你确定要删除这条记录?', function(r){
				if (r){
					var jsonData = JSON.parse('{'+'"appId":"' + row.appId + '"'+'}');
					$.restfulGet(`/esaas-sdcenter-agent/api/sd/app/delete/${row.appId}`, null, function(data){
						$.restfulDelete('../../api/paas/apps/info', jsonData, function(data) {
							$.messager.alert('提示','记录删除成功!','info');
							$('#dg').datagrid('reload');
						});
					})
				}
			});
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}

	function doView(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
			JLEUtil.createModalWin('详情','PaasAppsInfoView.html?' + '&appId=' + row.appId);
		} else {
			$.messager.alert('提示','请选择一条记录！','info');
		}
	}
	
	function doSdDevIndex() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLUtil.linkNewPage('SdDevIndex.html?appId=' + row.appId + '&projectId=' + row.projectId);
		} else {
			$.messager.alert('提示','请选择一个应用！','info');
		}
	}
	
	function doSdCompile(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
            $.restfulGet('/esaas-sdcenter-agent/api/sd/compile/' + row.appId,null,function(data){
                if(data.flag == 'success'){
                    var urlLink = `../esaas-smcenter/BatchMonitor.html?batchSerialNo=${data.batchSerialNo}&batchId=${data.batchId}`;
                    JLUtil.linkNewPage(urlLink);
                } else {
                    $.messager.alert('提示',data.msg,'info');
                }
            });
		} else {
			$.messager.alert('提示','请选择一个应用！','info');
		}	
	}
	
	function doSdDeploy(){
		var row = $('#dg').datagrid('getSelected');
		if (row) {
            $.restfulGet('../../api/sd/deploy/' + row.appId, null,function(data){
                if(data.flag == 'success'){
                    var urlLink = `../esaas-smcenter/BatchMonitor.html?batchSerialNo=${data.batchSerialNo}&batchId=${data.batchId}`;
                    JLUtil.linkNewPage(urlLink);
                } else {
                    $.messager.alert('提示', data.msg, 'error');
                }
            });
		} else {
            $.messager.alert('提示','请选择一个应用！','info');
		}
	}
	
	function doSdPreview(){
		var row = $('#dg').datagrid('getSelected');
		if (row){
			$.restfulGet('/esaas-sdcenter-agent/api/sd/preview/url/' + row.appId,null,function(data){
				if(data.code == '0'){
					JLUtil.linkNewPage(data.rows);
				}					
			});
		} else {
			$.messager.alert('提示','请选择一个应用！','info');
		}
	}

	function doTemplateChg() {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			JLEUtil.createModalWin('应用创建步骤-选择应用模板', 'popPaasTemplateInfo.html?sysId=' + $.getUrlParam('sysId'));
		} else {
			$.messager.alert('提示','请选择一个应用！','info');
		}
	}

	function doPopPaasTemplateInfoCallBack(template) {
		var row = $('#dg').datagrid('getSelected');
		if (row){
			row.appTemplateId = template.appTemplateId;
			row.appTemplateName = template.appTemplateName;
			$.restfulPut('../../api/paas/apps/info', row, function(data) {
				$.messager.alert('提示','修改成功！','info');
				reloadList();
			});
		} else {
			//$.messager.alert('提示','请选择一个应用！','info');
		}
	}

	function reloadList(){
		$('#dg').datagrid('reload');
		JLEUtil.closewin();
	};


	function generateCode() {
		var batchId = subsCode + '-CRT';
		$.restfulGet('../../api/bat/batch/info/action/gencode/', {
			batchSerialNo: 'none',//由后台使用时间戳作为批次流水号
			batchId: batchId,
			batchAction: 'run'
		}, function(data){
			if(data.code == '0') {
				JLUtil.linkNewPage('BatchMonitor.html?batchId='+batchId+'&batchSerialNo='+data.rows);
			} else {
				$.messager.alert('提示', data.message,'error');
			}
		});
	}
	function generateToGitee() {
		var batchId = subsCode + '-CRT-GITEE';
		$.restfulGet('../../api/bat/batch/info/action/gencode/', {
			batchSerialNo: 'none',//由后台使用时间戳作为批次流水号
			batchId: batchId,
			batchAction: 'run'
		}, function(data){
			if(data.code == '0') {
				JLUtil.linkNewPage('BatchMonitor.html?batchId='+batchId+'&batchSerialNo='+data.rows);
			} else {
				$.messager.alert('提示', data.message,'error');
			}
		});
	}

	$(function(){

	})
</script>
</head>
<body class="easyui-layout">
<div data-options="region:'north',title:''" class="divSearchBar">
	<form id="searchForm" >
		<table>
			<tr>
				<td>&nbsp;应用代码：</td>
				<td><input name="appCode" id="appCode"/></td>
				<td>&nbsp;应用名称：</td>
				<td><input name="appName" id="appName"/></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.queryForm('searchForm','dg','../../api/paas/apps/infos?sysCode=' + subsCode );">查找</a></td>
				<td><a class="easyui-linkbutton" href="javascript:void(0);" onclick="JLEUtil.clearForm('searchForm');">清空</a></td>
			</tr>
		</table>
	</form>
</div>
<div data-options="region:'center',split:false">
<table id="dg" class="easyui-datagrid" title="" style="width:100%;height:100%"
			data-options="singleSelect:true,collapsible:true,url:'../../api/paas/apps/infos?sysCode=' + subsCode,method:'post'"
			toolbar="#tb"
		title="Load Data" 
		rownumbers="true" pagination="true" pageSize="20">
		<thead>
			<tr>
				<th data-options="field:'appId',resizable:true" hidden="true">应用标识</th>
				<th data-options="field:'appCode',resizable:true" >应用代码</th>
				<th data-options="field:'appName',resizable:true" >应用名称</th>
				<th data-options="field:'archType',resizable:true" formatter="formatter_ARCH_TYPE">架构类型</th>
				<th data-options="field:'appVersion',resizable:true" >应用版本</th>
				<th data-options="field:'appOrder',resizable:true" hidden="true">应用排列顺序</th>
				<th data-options="field:'sysId',resizable:true" hidden="true">系统ID</th>
				<th data-options="field:'sysCode',resizable:true" hidden="true">所属系统代码</th>
				<th data-options="field:'sysName',resizable:true" hidden="true">所属系统名称</th>
				<th data-options="field:'projectId',resizable:true" hidden="true">数据库工程标识</th>
				<th data-options="field:'projectCode',resizable:true" hidden="true">表模型工程代码</th>
				<th data-options="field:'projectName',resizable:true" hidden="true">表模型工程名称</th>
				<th data-options="field:'appTemplateId',resizable:true" hidden="true">应用模板标识</th>
				<th data-options="field:'appTemplateName',resizable:true" >应用模板名称</th>
				<th data-options="field:'appActionCode',resizable:true" formatter="formatter_APP_ACTION_CODE" hidden="true">应用操作</th>
				<th data-options="field:'appActionState',resizable:true" formatter="formatter_APP_ACTION_STATE">操作状态</th>
				<th data-options="field:'createUser',resizable:true" >创建人</th>
				<th data-options="field:'createTime',resizable:true" >创建时间</th>
				<th data-options="field:'lastUpdateUser',resizable:true" >最后修改人</th>
				<th data-options="field:'lastUpdateTime',resizable:true" >最后更新时间</th>
			</tr>
		</thead>
	</table>
</div>
<div id="tb" style="padding:1px">
	<div style="margin-bottom:2px">
<!--		<a href="#" class="easyui-menubutton" data-options="menu:'#appCreareMenu',iconCls:'icon-add'" plain="true">应用创建向导</a>-->
<!--		<a href="javascript:doSdDevIndex()" class="easyui-linkbutton" iconCls="icon-more" plain="true">应用自助开发控制台</a>-->
		<a href="javascript:doSdCompile()" class="easyui-linkbutton" iconCls="icon-more" plain="true">应用编译</a>
		<a href="javascript:doSdDeploy()" class="easyui-linkbutton" iconCls="icon-more" plain="true">应用发布</a>
		<a href="javascript:doSdPreview()" class="easyui-linkbutton" iconCls="icon-more" plain="true">应用预览</a>
		<a href="#" class="easyui-menubutton" data-options="menu:'#appMangeMenu',iconCls:'icon-tip'" plain="true">应用管理</a>
		<a href="#" class="easyui-menubutton" data-options="menu:'#exportMenu',iconCls:'icon-tip'" plain="true">应用文档</a>

		<a class="easyui-linkbutton" href="javascript:void(0);" onclick="generateCode()">发布代码到本地</a>
		<a class="easyui-linkbutton" href="javascript:void(0);" onclick="generateToGitee()">发布代码到giteee仓库</a>
		</div>
</div>
	<div id="appCreareMenu" style="width: 180px;">
		<div onclick="doCreateApp()">新创建saas应用</div>
		<div onclick="doCreateApp()">创建saas应用市场中的应用</div>
	</div>
	<div id="appMangeMenu" style="width: 150px;">
		<div onclick="doTemplateChg()">更改应用模板</div>
		<div onclick="doDelete()">删除应用</div>
	</div>
	<div id="exportMenu" style="width: 150px;">
		<div onclick="doGenerateWord()">应用概要设计文档</div>
		<div onclick="doGenerateScript()">应用详细设计文档</div>
	</div>

</body>
</html>